<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('序号')" prop="num">
            <el-input-number v-model="form.num" :placeholder="$t('序号')" :controls="false" :precision="0" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('风险债券名称')" prop="name">
            <el-input v-model="form.name" :placeholder="$t('风险债券名称')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('风险债券编码')" prop="number">
            <el-input v-model="form.number" :placeholder="$t('风险债券编码')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('风险债券市值(元)')" prop="marketValue">
            <Money v-model="form.marketValue" :placeholder="$t('风险债券市值(元)')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('风险债券估值依据')" prop="valuationBasis">
            <el-select v-model="form.valuationBasis" :placeholder="$t('风险债券估值依据')">
              <el-option value="A-交易所、银行间市场交易数据" />
              <el-option value="B-第三方估值机构数据" />
              <el-option value="C-管理人、托管、其他外包服务机构估值数据" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('风险债券成本(元)')" prop="cost">
            <Money v-model="form.cost" :placeholder="$t('风险债券成本(元)')" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('风险债券负面情况类别')" prop="negative">
            <el-select v-model="form.negative" multiple :placeholder="$t('风险债券负面情况类别')">
              <el-option value="A-持有债券的发行主体无法兑付其他相关债务融资工具" />
              <el-option value="B-持有的债券评级被调降，且该债券目前评级已低于AA+（即AA及以下）" />
              <el-option value="C-持有的债券评级展望为负面，且该债券目前评级已低于AA+（即AA及以下）" />
              <el-option value="D-持有的债券的发行主体出现重大负面情况，产品管理人认为其无法正常兑付" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('风险债券发行日期')" prop="issuedDate">
            <el-date-picker
              v-model="form.issuedDate"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('风险债券发行日期')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('风险债券到期时间')" prop="expireDate">
            <el-date-picker
              v-model="form.expireDate"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('风险债券到期时间')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('风险债券面值')" prop="faceValue">
            <Money v-model="form.faceValue" :placeholder="$t('风险债券面值')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('风险债券类别')" prop="type">
            <el-select v-model="form.type" :placeholder="$t('风险债券类别')">
              <el-option :value="$t('国债')" />
              <el-option :value="$t('地方政府债')" />
              <el-option :value="$t('央行票据')" />
              <el-option :value="$t('政策性金融债')" />
              <el-option :value="$t('其他金融债')" />
              <el-option :value="$t('企业债')" />
              <el-option :value="$t('公司债')" />
              <el-option :value="$t('中期票据')" />
              <el-option :value="$t('短期融资券')" />
              <el-option :value="$t('定向工具')" />
              <el-option :value="$t('国际机构债')" />
              <el-option :value="$t('政府支持机构债')" />
              <el-option :value="$t('资产支持证券')" />
              <el-option :value="$t('可转债')" />
              <el-option :value="$t('可交换债')" />
              <el-option :value="$t('可分离转债存债')" />
              <el-option :value="$t('私募债')" />
              <el-option :value="$t('其他')" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('发生风险前债项评级')" prop="debtRating">
            <el-input v-model="form.debtRating" type="textarea" :placeholder="$t('发生风险前债项评级')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('最新债项评级')" prop="latestDebtRating">
            <el-input v-model="form.latestDebtRating" type="textarea" :placeholder="$t('最新债项评级')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('债券担保情况说明')" prop="situationDesc">
            <el-input v-model="form.situationDesc" type="textarea" :placeholder="$t('债券担保情况说明')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否为城投债')" prop="cityInvestBond">
            <el-select v-model="form.cityInvestBond" :placeholder="$t('是否为城投债')">
              <el-option value="1-是" />
              <el-option value="0-否" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('债券发行主体名称')" prop="issuedSubjectName">
            <el-input v-model="form.issuedSubjectName" :placeholder="$t('债券发行主体名称')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('债券发行主体统一社会信用代码')" prop="socialCreditCode">
            <el-input v-model="form.socialCreditCode" :placeholder="$t('债券发行主体统一社会信用代码')" show-word-limit maxlength="18" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('发债企业类型1')" prop="enterpriseTypeFirst">
            <el-select v-model="form.enterpriseTypeFirst" :placeholder="$t('发债企业类型1')">
              <el-option value="A-上市公司" />
              <el-option value="B-新三板挂牌公司" />
              <el-option value="C-未上市未挂牌企业" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('发债企业类型2')" prop="enterpriseTypeSecond">
            <el-select v-model="form.enterpriseTypeSecond" :placeholder="$t('发债企业类型2')">
              <el-option value="A-中央国有企业" />
              <el-option value="B-地方国有企业" />
              <el-option value="C-民营企业" />
              <el-option value="D-外资企业" />
              <el-option value="E-其他企业" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('发债企业所属地区')" prop="area">
            <el-cascader
              v-model="form.area"
              :options="areaOptions"
              :props="{ value: 'name', label: 'name' }"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('发债企业所属行业')" prop="industry">
            <el-select v-model="form.industry" :placeholder="$t('发债企业所属行业')" filterable>
              <el-option value="能源开采设备与服务" />
              <el-option value="石油与天然气" />
              <el-option value="煤炭" />
              <el-option value="化学原料" />
              <el-option value="化学制品" />
              <el-option value="建筑材料" />
              <el-option value="容器与包装" />
              <el-option value="有色金属" />
              <el-option value="钢铁" />
              <el-option value="非金属采矿及制品" />
              <el-option value="纸类与林业产品" />
              <el-option value="航空航天与国防" />
              <el-option value="建筑产品" />
              <el-option value="建筑与工程" />
              <el-option value="电气设备" />
              <el-option value="工业集团企业" />
              <el-option value="机械制造" />
              <el-option value="环保设备、工程与服务" />
              <el-option value="商业服务与用品" />
              <el-option value="航空货运与物流" />
              <el-option value="航空公司" />
              <el-option value="航运" />
              <el-option value="道路运输" />
              <el-option value="交通基本设施" />
              <el-option value="汽车零配件与轮胎" />
              <el-option value="汽车与摩托车" />
              <el-option value="家庭耐用消费品" />
              <el-option value="休闲设备与用品" />
              <el-option value="纺织服装" />
              <el-option value="珠宝与奢侈品" />
              <el-option value="酒店、餐馆与休闲" />
              <el-option value="综合消费者服务" />
              <el-option value="传媒" />
              <el-option value="日用品经销商" />
              <el-option value="互联网零售" />
              <el-option value="多元化零售" />
              <el-option value="其他零售" />
              <el-option value="食品与主要用品零售" />
              <el-option value="饮料" />
              <el-option value="包装食品与肉类" />
              <el-option value="烟草" />
              <el-option value="农牧渔产品" />
              <el-option value="家常用品" />
              <el-option value="个人用品" />
              <el-option value="医疗器械" />
              <el-option value="医疗用品与服务提供商" />
              <el-option value="生物科技" />
              <el-option value="制药" />
              <el-option value="制药与生物科技服务" />
              <el-option value="商业银行" />
              <el-option value="抵押信贷机构" />
              <el-option value="其他金融服务" />
              <el-option value="消费信贷" />
              <el-option value="资本市场" />
              <el-option value="保险" />
              <el-option value="房地产开发与园区" />
              <el-option value="房地产管理与服务" />
              <el-option value="房地产投资信托(REITs)" />
              <el-option value="互联网服务" />
              <el-option value="信息技术服务" />
              <el-option value="软件开发" />
              <el-option value="电脑与外围设备" />
              <el-option value="电子设备" />
              <el-option value="半导体" />
              <el-option value="电信运营服务" />
              <el-option value="电信增值服务" />
              <el-option value="通信设备" />
              <el-option value="电力" />
              <el-option value="燃气" />
              <el-option value="供热或其他公用事业" />
              <el-option value="水务" />
              <el-option value="电网" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('发生风险前主体评级')" prop="subjectRating">
            <el-input v-model="form.subjectRating" type="textarea" :placeholder="$t('发生风险前主体评级')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')" prop="remark">
            <el-input v-model="form.remark" type="textarea" :placeholder="$t('备注')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div v-if="!btnHide && processBtn" slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="fund:monitor" />
    </div>
  </div>
</template>

<script>
    import { saveFundRiskBond, getFundRiskBond } from '@/api/fund/operation/fundRiskBond'
    import { treeSelect } from '@/api/system/area/sysArea'
    export default {
        data() {
            return {
                // 表单参数
                form: {},
                // 遮罩层
                loading: false,
                areaOptions: [],
                // 表单校验
                rules: {
                name: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                ],
                socialCreditCode: { message: this.$t('只能输入数字或字母'), pattern: /^[a-z0-9]+$/i, trigger: 'blur' }
                },
              processBtn: false,
              btnHide: false
            }
        },
        created() {
          treeSelect({ parentId: '1' }).then(res => {
            this.areaOptions = res.data
          })
        },
        methods: {
            // 初始化数据
            init(data) {
                this.processBtn = data.processBtn
                this.btnHide = data.btnHide
                this.loading = true
                if (data.id !== undefined) {
                    getFundRiskBond(data.id).then(response => {
                        this.form = response.data
                        this.loading = false
                    })
                } else {
                    this.reset()
                    this.form.monitorId = data.monitorId
                    this.form.num = data.total + 1
                    this.loading = false
                }
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,

                    monitorId: undefined,

                    name: undefined,

                    number: undefined,

                    marketValue: undefined,

                    valuationBasis: undefined,

                    cost: undefined,

                    negative: undefined,

                    issuedDate: undefined,

                    expireDate: undefined,

                    faceValue: undefined,

                    type: undefined,

                    debtRating: undefined,

                    latestDebtRating: undefined,

                    situationDesc: undefined,

                    cityInvestBond: undefined,

                    issuedSubjectName: undefined,

                    socialCreditCode: undefined,

                    enterpriseTypeFirst: undefined,

                    enterpriseTypeSecond: undefined,

                    area: undefined,

                    industry: undefined,

                    subjectRating: undefined,

                    remark: undefined

                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                  this.$parent.$parent.formOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveFundRiskBond(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                       this.locationError(document)
                    }
                })
           }

        }

    }
</script>
